package com.sky.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单接口")
@RestController
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 取消订单接口
     */

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result reminder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        // 根据id取消订单
        ordersService.cancel(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 各种状态的订单数量统计
     */
    @ApiOperation("各个状态的订单统计")
    @GetMapping("//statistics")
    public Result<OrderOverViewVO> statistics() {
        return Result.success(ordersService.countStatus());
    }

    /**
     * 根据id完成订单
     */
    @ApiOperation("完成订单")
    @PutMapping("complete/{id}")
    public Result complete(@PathVariable Long id) {
        ordersService.complete(id);
        return Result.success();
    }

    /**
     * 拒单接口
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        ordersService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 接单
     *
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody Long id) {
        ordersService.confirm(id);
        return Result.success();
    }

    /**
     * 根据id查询订单详情
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id) {
        return Result.success(ordersService.getOrderDetailsById(id));
    }
    /**
     * 订单搜索接口
     */
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<IPage<Orders>> search(@RequestParam Integer page, @RequestParam Integer pageSize, OrdersPageQueryDTO ordersPageQueryDTO) {
        IPage<Orders> page1 = new Page<>(page, pageSize);
        IPage<Orders> list = ordersService.listOredsers(page1, ordersPageQueryDTO);
        return Result.success(list);
    }
    /**
     * 派送订单
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id) {
        ordersService.delivery(id);
        return Result.success();
    }
}
